home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / wb / muispeak.lha / src / Main.c < prev    next >
C/C++ Source or Header  |  1994-11-28  |  8KB  |  375 lines

  1. #include <intuition/intuition.h>
  2.  
  3. #include <libraries/mui.h>
  4. #include <libraries/locale.h>
  5. #include <libraries/gadtools.h>
  6. #include <libraries/translator.h>
  7. #include <proto/uebersetzer.h>
  8.  
  9. #include <clib/locale_protos.h>
  10. #include <clib/muimaster_protos.h>
  11. #include <clib/alib_protos.h>
  12. #include <clib/dos_protos.h>
  13. #include <clib/exec_protos.h>
  14. #include <devices/narrator.h>
  15.  
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18.  
  19. #include "speak.h"
  20.  
  21.  
  22. #define CATCOMP_BLOCK
  23. #include "speakstrings_cat.h"
  24.  
  25. #undef CATCOMP_BLOCK
  26.  
  27. #define DEFAULT_STR        "Hallo, ich bin der sprechende Amiga"
  28.  
  29. BYTE audio_chn[3][4] ={ {1,8,0,0},  {2,4,0,0}, {3,5,10,12} };
  30.  
  31. struct Library *        TranslatorBase;
  32. struct Library *        UebersetzerBase;
  33. struct LocaleBase *     LocaleBase;
  34. struct Library *         MUIMasterBase;
  35. struct MsgPort *        SpeakMP;
  36.  
  37. struct Locale *            locale = NULL;
  38. struct Catalog *        Catalog = NULL;
  39.  
  40. struct narrator_rb *     SpeakIO;
  41. struct ObjApp *         App    = NULL;
  42.  
  43. int LANGUAGE = 0;
  44. int PITCH    = 120;
  45. int SPEED    = 120;
  46. int VOLUME    = 64;
  47. int SEX        = MALE;
  48. int KIND    = ROBOTICF0;
  49. int ENTHU   = 0;
  50. int PERTUB  = 0;
  51. int OUTPUT_CHANNEL =2;
  52. int F1ADJ    = 0;
  53. int F2ADJ    = 0;
  54. int F3ADJ    = 0;
  55. int A1ADJ    = 0;
  56. int A2ADJ    = 0;
  57. int A3ADJ    = 0;
  58. int ARTIC    = 0;
  59. int AVBIAS    = 0;
  60. int AFBIAS    = 0;
  61. int CENT    = 0;
  62.  
  63. /****************************************************************/
  64.  
  65. void main(int argc,char **argv);
  66.  
  67. /****************************************************************/
  68.  
  69. int wbmain(struct WBStartup *wb_startup)
  70. {
  71.  
  72.     main(0, NULL);
  73. }
  74.  
  75. /****************************************************************/
  76.  
  77. void MyOutput(char *str)
  78. {
  79.     Write(Output(),str,strlen(str));
  80. }
  81.  
  82. /****************************************************************/
  83.  
  84. char * MyTranslate(char * str)
  85. {
  86.     char ph_buf[255];
  87.  
  88.     if (LANGUAGE == 0)
  89.     {
  90.         TranslateGerman(str , strlen(str) , (APTR) ph_buf , 255);
  91.     }
  92.     else 
  93.     {
  94.         Translate(str , strlen(str) , (APTR) ph_buf , 255);
  95.     }        
  96.  
  97.     return ph_buf;
  98. }
  99.  
  100. /****************************************************************/
  101.  
  102. void Speak(char *str)
  103. {
  104.     static char ph_buf[255];
  105.  
  106.     if (LANGUAGE == 0)
  107.     {
  108.         TranslateGerman(str , strlen(str) , (APTR) ph_buf , 255);
  109.     }
  110.     else 
  111.     {
  112.         Translate(str , strlen(str) , (APTR) ph_buf , 255);
  113.     }        
  114.  
  115.     set( App->TX_PHONEME , MUIA_Text_Contents,ph_buf);
  116.  
  117.     set( App->STR_TEXT , MUIA_String_BufferPos , 0);
  118.  
  119.  
  120.     SpeakIO->message.io_Command    = CMD_WRITE;
  121.     SpeakIO->message.io_Offset    = 0;
  122.     SpeakIO->message.io_Data    = ph_buf;
  123.     SpeakIO->message.io_Length    = strlen( ph_buf );
  124.  
  125.     SpeakIO->ch_masks            = audio_chn[OUTPUT_CHANNEL];
  126.     SpeakIO->nm_masks            = sizeof(audio_chn)/3;
  127.     SpeakIO->rate                = SPEED;
  128.     SpeakIO->pitch                = PITCH;
  129.     SpeakIO->volume                = VOLUME;
  130.     SpeakIO->sex                = SEX;
  131.     SpeakIO->mode                = KIND;
  132.     SpeakIO->F0enthusiasm        = ENTHU;
  133.     SpeakIO->F0perturb            = PERTUB;
  134.  
  135.     SpeakIO->F1adj                = F1ADJ;
  136.     SpeakIO->F1adj                = F2ADJ;
  137.     SpeakIO->F1adj                = F3ADJ;
  138.     SpeakIO->A1adj                = A1ADJ;
  139.     SpeakIO->A2adj                = A2ADJ;
  140.     SpeakIO->A3adj                = A3ADJ;
  141.     SpeakIO->articulate            = ARTIC;
  142.     SpeakIO->AVbias                = AVBIAS;
  143.     SpeakIO->AFbias                = AFBIAS;
  144.     SpeakIO->centralize            = CENT;
  145.     
  146.     DoIO((struct IORequest *) SpeakIO);
  147. }
  148.  
  149. /****************************************************************/
  150.  
  151. void init(void)
  152. {
  153.     if (!(MUIMasterBase =  OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  154.     {
  155.         MyOutput("Can't open muimaster.library V 37+\n");
  156.         exit(0);
  157.     }
  158.     
  159.  
  160.     if (!(UebersetzerBase = OpenLibrary("uebersetzer.library",0)))
  161.     {
  162.         MyOutput("Can't open uebersetzer.library\n");
  163.         CloseLibrary(MUIMasterBase);
  164.         exit(0);
  165.     }
  166.  
  167.  
  168.     if (!(TranslatorBase = OpenLibrary("translator.library",0)))
  169.     {
  170.         MyOutput("Can't open translator.library\n");
  171.         CloseLibrary(MUIMasterBase);
  172.         exit(0);
  173.     }
  174.  
  175.  
  176.     SpeakMP = CreateMsgPort();
  177.     SpeakIO = (struct narrator_rb *) CreateExtIO(SpeakMP,sizeof(struct narrator_rb));
  178.     SpeakIO->flags = NDF_NEWIORB;
  179.                 
  180.     OpenDevice("narrator.device",0,(struct IORequest *) SpeakIO,NULL);
  181. }
  182.  
  183. /****************************************************************/
  184.  
  185. void main(int argc,char **argv)
  186. {
  187.     BOOL    running = TRUE;
  188.     ULONG    signal;
  189.  
  190.  
  191.     LocaleBase = (struct LocaleBase *) OpenLibrary("locale.library",37);
  192.  
  193.     if (LocaleBase != NULL)
  194.     {
  195.         struct TagItem tags[3];
  196.     
  197.         locale = OpenLocale(NULL);
  198.  
  199.         if (strcmp(locale->loc_LanguageName,"deutsch.language"))   // Builtin language != locale Language
  200.         {
  201.             tags[0].ti_Tag  = OC_BuiltInLanguage;
  202.             tags[0].ti_Data = (ULONG) "deutsch";    
  203.  
  204.             tags[1].ti_Tag  = OC_Version;
  205.             tags[1].ti_Data = (ULONG) 1;
  206.  
  207.             tags[2].ti_Tag  = OC_BuiltInCodeSet;    // Default, requested from Commodore
  208.             tags[2].ti_Data = (ULONG) 0;
  209.  
  210.             Catalog=OpenCatalogA(NULL,"muispeak.catalog",tags);
  211.  
  212.          }
  213.     }    
  214.  
  215.     init();
  216.  
  217.     App = CreateApp();
  218.  
  219.     get(App->CY_SEX,MUIA_Cycle_Active,&SEX);
  220.     get(App->CY_KIND,MUIA_Cycle_Active,&KIND);
  221.     get(App->SL_SPEED,MUIA_Slider_Level,&SPEED);
  222.     get(App->SL_HEIGHT,MUIA_Slider_Level,&PITCH);
  223.     get(App->SL_VOLUME,MUIA_Slider_Level,&VOLUME);
  224.     get(App->SL_PERTUBATION,MUIA_Slider_Level,&PERTUB);
  225.     get(App->SL_ENTHUSIASMUS,MUIA_Slider_Level,&ENTHU);
  226.  
  227.     set(App->CY_OUTPUT,MUIA_Cycle_Active,&OUTPUT_CHANNEL);
  228.  
  229.     
  230.     setstring( App->STR_TEXT , DEFAULT_STR);
  231.     set( App->TX_PHONEME , MUIA_Text_Contents,MyTranslate(DEFAULT_STR));
  232.  
  233.  
  234.     while (running)
  235.     {
  236.         switch (DoMethod(App->App,MUIM_Application_Input,&signal))    
  237.         {
  238.             case RET_SPEAK:
  239.                 char *x;
  240.                 get(App->STR_TEXT,MUIA_String_Contents,&x);
  241.                 Speak(x);
  242.                 break;
  243.  
  244.             case RET_SEX:
  245.                 get(App->CY_SEX,MUIA_Cycle_Active,&SEX);
  246.                 break;
  247.  
  248.             case RET_KIND:
  249.                 get(App->CY_KIND,MUIA_Cycle_Active,&KIND);
  250.                 break;
  251.  
  252.             case RET_OUTPUT:
  253.                 get(App->CY_OUTPUT,MUIA_Cycle_Active,&OUTPUT_CHANNEL);
  254.                 break;
  255.  
  256.             case RET_LANGUAGE:
  257.                 char *x;
  258.                 get(App->CY_LANGUAGE,MUIA_Cycle_Active,&LANGUAGE);
  259.                 get(App->STR_TEXT,MUIA_String_Contents,&x);
  260.                 set( App->TX_PHONEME , MUIA_Text_Contents, MyTranslate(x));
  261.                 set( App->STR_TEXT , MUIA_String_BufferPos , 0);
  262.                 break;
  263.  
  264.             case RET_SPEED:
  265.                 get(App->SL_SPEED,MUIA_Slider_Level,&SPEED);
  266.                 break;
  267.  
  268.             case RET_HEIGHT:
  269.                 get(App->SL_HEIGHT,MUIA_Slider_Level,&PITCH);
  270.                 break;
  271.  
  272.             case RET_VOLUME:
  273.                 get(App->SL_VOLUME,MUIA_Slider_Level,&VOLUME);
  274.                 break;
  275.  
  276.             case RET_PERTUB:
  277.                 get(App->SL_PERTUBATION,MUIA_Slider_Level,&PERTUB);
  278.                 break;
  279.  
  280.             case RET_ENTHU:
  281.                 get(App->SL_ENTHUSIASMUS,MUIA_Slider_Level,&ENTHU);
  282.                 break;
  283.             
  284.             case RET_F1ADJ:
  285.                 get(App->SL_F1ADJ,MUIA_Slider_Level,&F1ADJ );
  286.                 break;    
  287.  
  288.             case RET_F2ADJ:
  289.                 get(App->SL_F2ADJ,MUIA_Slider_Level,&F2ADJ );
  290.                 break;    
  291.  
  292.             case RET_F3ADJ:
  293.                 get(App->SL_F3ADJ,MUIA_Slider_Level,&F3ADJ );
  294.                 break;    
  295.  
  296.             case RET_A1ADJ:
  297.                 get(App->SL_A1ADJ,MUIA_Slider_Level,&A1ADJ );
  298.                 break;    
  299.  
  300.             case RET_A2ADJ:
  301.                 get(App->SL_A2ADJ,MUIA_Slider_Level,&A2ADJ );
  302.                 break;    
  303.  
  304.             case RET_A3ADJ:
  305.                 get(App->SL_A3ADJ,MUIA_Slider_Level,&A3ADJ );
  306.                 break;    
  307.  
  308.             case RET_AFBIAS:
  309.                 get(App->SL_AFBIAS,MUIA_Slider_Level,&AFBIAS);
  310.                 break;    
  311.  
  312.             case RET_AVBIAS:
  313.                 get(App->SL_AVBIAS,MUIA_Slider_Level,&AVBIAS);
  314.                 break;    
  315.  
  316.             case RET_ARTIC:
  317.                 get(App->SL_ARTIC,MUIA_Slider_Level,&ARTIC);
  318.                 break;    
  319.  
  320.             case RET_CENT:
  321.                 get(App->SL_CENT,MUIA_Slider_Level,&CENT);
  322.                 break;    
  323.  
  324.             case RET_TEXT:
  325.                 char *x;
  326.                 get(App->STR_TEXT,MUIA_String_Contents,&x);
  327.                 set( App->TX_PHONEME , MUIA_Text_Contents, MyTranslate(x));
  328.                 set( App->STR_TEXT , MUIA_String_BufferPos , 0);
  329.                 break;
  330.  
  331.             case MUIV_Application_ReturnID_Quit:
  332.                 running = FALSE;
  333.                         break;
  334.         }
  335.  
  336.         if (running && signal) Wait(signal);
  337.  
  338.     }        
  339.  
  340.     
  341.  
  342.     CloseDevice((struct IORequest *) SpeakIO);
  343.     DeleteIORequest((struct IORequest *) SpeakIO);
  344.     DeleteMsgPort(SpeakMP);
  345.  
  346.     DisposeApp(App);
  347.     CloseLibrary(MUIMasterBase);
  348.     CloseLibrary(UebersetzerBase);
  349.     CloseLibrary(TranslatorBase);
  350.     CloseLibrary((struct Library *) LocaleBase);
  351. }
  352.  
  353.  
  354. char * GetString(int stringNum)
  355. {
  356.     LONG   *l;
  357.     UWORD  *w;
  358.     STRPTR  builtIn;
  359.  
  360.     l = (LONG *)CatCompBlock;
  361.  
  362.     while (*l != stringNum)
  363.     {
  364.         w = (UWORD *)((ULONG)l + 4);
  365.         l = (LONG *)((ULONG)l + (ULONG)*w + 6);
  366.     }
  367.     builtIn = (STRPTR)((ULONG)l + 6);
  368.  
  369.  
  370.     if (LocaleBase)
  371.         return(GetCatalogStr(Catalog,stringNum,builtIn));
  372.  
  373.     return(builtIn);}
  374.  
  375.